/**
 * 
 */
package com.geekteam.masterenglish.utils;

import com.geekteam.masterenglish.entity.DataRequest;

/**
 * @author MTROL
 * 
 */
public class NetworkUtils {
	public static final String PUBLIC_KEY = "141d552a2ad69e0527c79956f81aa7bf49ea1594";
	public static final String PRIVATE_KEY = "b26a978d02eaf47c77a0e45898b1f897";
	public static final String DOMAIN = "http://api.mp3.zing.vn/api/";

	public static String getLinkRequest(String function, DataRequest entity) {
		if (entity == null) {
			return getLinkRequest(function, "");
		}

		String json = JsonUtil.toJson(entity);
		return getLinkRequest(function, json);
	}

	private static String getLinkRequest(String function, String json) {
		String result = null;

		if (json.equals("")) {
			String signature = Utils.hmacMD5("", PRIVATE_KEY, "HMACMD5");
			result = DOMAIN + function + "?publicKey=" + PUBLIC_KEY
					+ "&signature=" + signature;
		} else {
			String data = Utils.base64(json);
			String signature = Utils.hmacMD5(data, PRIVATE_KEY, "HMACMD5");
			result = DOMAIN + function + "?publicKey=" + PUBLIC_KEY
					+ "&signature=" + signature + "&jsondata=" + data;
		}

		return result;
	}
}
